#include <stdio.h>
#include <stdlib.h>
#include "ManageSystem.h"

void test01();
void test02();
void test03();
void test04();
void test05();
void test06();

int main(){

    int writeFlag = 0;
    PeoManage peoManage;

    AccountType accountType;        //账户类型
    int index = -1;                 //数组下标
    int id = -1;
    int input = 0;
    int select = 0;

    ManageSysReadDate(&peoManage,&writeFlag);

    if(writeFlag != WRITE_FLAG){    //文件为空初始化peoManage
        ManageSysInit(&peoManage);
    }

    do{

        SCREENCLEAN();
        ManageSysShowLogin();
        printf("请输入>");
        scanf("%d",&select);

        if(select == LOGIN){

            ManageSysLogin(&peoManage,&accountType,&id,&index);

            if(accountType == STUACCOUNT){

                do{

                    ManageSysShowMenuStu();
                    printf("\n请输入选择>");
                    scanf("%d",&input);

                    switch(input){
                        
                        case STU_SHOWMYMESSAGE:
                            ManageSysShowMyMessageStu(&peoManage,id);
                            break;
                        case STU_CHANGEMYMESSAGE:
                            ManageSysChangeMyMessageStu(&peoManage,id);
                            printf("请重新登录\n");
                            input = 0;
                            break;
                        case STU_SHOWALLSCORE:
                            ManageSysShowAllScoreStu(&peoManage);
                            break;
                        case STU_SORTBYID:
                            ManageSysSortStuById(&peoManage);
                            break;
                        case STU_SORTBYSCORE:
                            ManageSysSortStuByScore(&peoManage);
                            break;
                        case EXIT:
                            break;
                        default:
                            printf("输入有误");
                            break;
                    }

                    PRESS_CONTINUE();
                    SCREENCLEAN();

                }while(input);
            }
            else if(accountType == TEAACCOUNT){
                
                do{

                    ManageSysShowMenuTea();
                    printf("\n请输入选择>");
                    scanf("%d",&input);

                    switch(input){
                        
                        case TEA_SHOWMYMESSAGE:
                            ManageSysShowMyMessageTea(&peoManage,id);
                            break;
                        case TEA_CHANGEMYMESSAGE:
                            ManageSysChangeMyMessageTea(&peoManage,id);
                            printf("请重新登录\n");
                            input = 0;
                            break;
                        case TEA_SHOWALLTEAMESSAGE:
                            ManageSysShowAllTeaMessageTea(&peoManage);
                            break;
                        case TEA_SORTTEABYID:
                            ManageSysSortTeaByIdTea(&peoManage);
                            break;
                        case TEA_SHOWALLSTUMESSAGE:
                            ManageSysShowAllStuMessageTea(&peoManage);
                            break;
                        case TEA_ADDSTU:
                            ManageSysAddStuTea(&peoManage);
                            break;
                        case TEA_CHANGESTUMESSAGE:
                            ManageSysChangeStuMessageTea(&peoManage);
                            break;
                        case TEA_CHANGESTUSCORE:
                            ManageSysChangeStuScoreTea(&peoManage);
                            break;
                        case TEAT_DELSTU:
                            ManageSysDelStuTea(&peoManage);
                            break;
                        case TEA_SORTALLSTUBYID:
                            ManageSysSortStuById(&peoManage);
                            break;
                        case TEA_SORTALLSTUBYSCORE:
                            ManageSysSortStuByScore(&peoManage);
                            break;
                        case EXIT:
                            break;
                        default:
                            printf("输入有误");
                            break;
                    }

                    PRESS_CONTINUE();
                    SCREENCLEAN();

                }while(input);
                
            }
            else if(accountType == ROOTACCOUNT){

                do{

                    ManageSysShowMenuRoot();
                    printf("请输入选择>");
                    scanf("%d",&input);

                    switch(input){

                        case ROOT_SHOWALL:
                            ManageSysShowAllMessage(&peoManage);
                            break;
                        case EXIT:
                            printf("退出\n");
                            break;
                        default:
                            printf("输入有误\n");
                            break;
                    }

                    PRESS_CONTINUE();
                    SCREENCLEAN();

                }while(input);
            }
        }
        else if(select == EXIT){

            printf("退出系统\n");
            ManageSysWriteDate(&peoManage);
            PRESS_CONTINUE();
            SCREENCLEAN();
        }
        else{

            printf("输入有误\n");
            PRESS_CONTINUE();
            SCREENCLEAN();
        }

    }while(select);

    return 0;
}



void test06(){

    int writeFlag = 0;
    PeoManage peoManage;

    AccountType accountType;        //账户类型
    int index = -1;                 //数组下标
    int id = -1;
    int input = 0;
    int select = 0;

    ManageSysReadDate(&peoManage,&writeFlag);

    if(writeFlag != WRITE_FLAG){    //文件为空初始化peoManage
        ManageSysInit(&peoManage);
    }

    do{

        SCREENCLEAN();
        ManageSysShowLogin();
        printf("请输入>");
        scanf("%d",&select);

        if(select == LOGIN){

            ManageSysLogin(&peoManage,&accountType,&id,&index);

            if(accountType == STUACCOUNT){

                do{

                    ManageSysShowMenuStu();
                    printf("\n请输入选择>");
                    scanf("%d",&input);

                    switch(input){
                        
                        case STU_SHOWMYMESSAGE:
                            ManageSysShowMyMessageStu(&peoManage,id);
                            break;
                        case STU_CHANGEMYMESSAGE:
                            ManageSysChangeMyMessageStu(&peoManage,id);
                            printf("请重新登录\n");
                            input = 0;
                            break;
                        case STU_SHOWALLSCORE:
                            ManageSysShowAllScoreStu(&peoManage);
                            break;
                        case STU_SORTBYID:
                            ManageSysSortStuById(&peoManage);
                            break;
                        case STU_SORTBYSCORE:
                            ManageSysSortStuByScore(&peoManage);
                            break;
                        case EXIT:
                            break;
                        default:
                            printf("输入有误");
                            break;
                    }

                    PRESS_CONTINUE();
                    SCREENCLEAN();

                }while(input);
            }
            else if(accountType == TEAACCOUNT){
                
                do{

                    ManageSysShowMenuTea();
                    printf("\n请输入选择>");
                    scanf("%d",&input);

                    switch(input){
                        
                        case TEA_SHOWMYMESSAGE:
                            ManageSysShowMyMessageTea(&peoManage,id);
                            break;
                        case TEA_CHANGEMYMESSAGE:
                            ManageSysChangeMyMessageTea(&peoManage,id);
                            printf("请重新登录\n");
                            input = 0;
                            break;
                        case TEA_SHOWALLTEAMESSAGE:
                            ManageSysShowAllTeaMessageTea(&peoManage);
                            break;
                        case TEA_SORTTEABYID:
                            ManageSysSortTeaByIdTea(&peoManage);
                            break;
                        case TEA_SHOWALLSTUMESSAGE:
                            ManageSysShowAllStuMessageTea(&peoManage);
                            break;
                        case TEA_ADDSTU:
                            ManageSysAddStuTea(&peoManage);
                            break;
                        case TEA_CHANGESTUMESSAGE:
                            ManageSysChangeStuMessageTea(&peoManage);
                            break;
                        case TEA_CHANGESTUSCORE:
                            ManageSysChangeStuScoreTea(&peoManage);
                            break;
                        case TEAT_DELSTU:
                            ManageSysDelStuTea(&peoManage);
                            break;
                        case TEA_SORTALLSTUBYID:
                            ManageSysSortStuById(&peoManage);
                            break;
                        case TEA_SORTALLSTUBYSCORE:
                            ManageSysSortStuByScore(&peoManage);
                            break;
                        case EXIT:
                            break;
                        default:
                            printf("输入有误");
                            break;
                    }

                    PRESS_CONTINUE();
                    SCREENCLEAN();

                }while(input);
                
            }
            else if(accountType == ROOTACCOUNT){

                do{

                    ManageSysShowMenuRoot();
                    printf("请输入选择>");
                    scanf("%d",&input);

                    switch(input){

                        case ROOT_SHOWALL:
                            ManageSysShowAllMessage(&peoManage);
                            break;
                        case EXIT:
                            printf("退出\n");
                            break;
                        default:
                            printf("输入有误\n");
                            break;
                    }

                    PRESS_CONTINUE();
                    SCREENCLEAN();

                }while(input);
            }
        }
        else if(select == EXIT){

            printf("退出系统\n");
            ManageSysWriteDate(&peoManage);
            PRESS_CONTINUE();
            SCREENCLEAN();
        }
        else{

            printf("输入有误\n");
            PRESS_CONTINUE();
            SCREENCLEAN();
        }

    }while(select);
}

void test05(){

    PeoManage peoManage;
    int writeFlag = 0;

    ManageSysReadDate(&peoManage,&writeFlag);

}

void test04(){

    int writeFlag = 0;
    PeoManage peoManage;
    ManageSysInit(&peoManage);

    //插入测试数据
    TeaManage* pTea = &peoManage.teaManage;
    StuManage* pStu = &peoManage.stuManage;

    StuInsert(pStu,1);
    StuInsert(pStu,2);
    StuInsert(pStu,3);
    StuInsert(pStu,4);
    StuInsert(pStu,5);
    StuInsert(pStu,6);
    StuInsert(pStu,7);

    StuInputScore(pStu,1);
    StuInputScore(pStu,2);
    StuInputScore(pStu,3);
    StuInputScore(pStu,4);
    StuInputScore(pStu,5);
    StuInputScore(pStu,6);
    StuInputScore(pStu,7);

    TeaInsert(pTea,1);
    TeaInsert(pTea,2);
    TeaInsert(pTea,2);
    TeaInsert(pTea,3);
    TeaInsert(pTea,5);
    TeaInsert(pTea,6);

    ManageSysWriteDate(&peoManage);

    ManageSysReadDate(&peoManage,&writeFlag);
}

void test03(){

    PeoManage peoManage;
    ManageSysInit(&peoManage);

    //插入测试数据
    TeaManage* pTea = &peoManage.teaManage;
    StuManage* pStu = &peoManage.stuManage;

    StuInsert(pStu,1);
    StuInsert(pStu,2);
    StuInsert(pStu,3);
    StuInsert(pStu,4);
    StuInsert(pStu,5);
    StuInsert(pStu,6);

    StuInputScore(pStu,1);
    StuInputScore(pStu,2);
    StuInputScore(pStu,3);
    StuInputScore(pStu,4);
    StuInputScore(pStu,5);
    StuInputScore(pStu,6);

    TeaInsert(pTea,1);
    TeaInsert(pTea,2);
    TeaInsert(pTea,2);
    TeaInsert(pTea,3);
    TeaInsert(pTea,5);
    TeaInsert(pTea,6);
    

    AccountType accountType;        //账户类型
    int index = -1;                 //数组下标
    int id = -1;
    int input = 0;

    while(1){

        SCREENCLEAN();
        ManageSysShowLogin();
        ManageSysLogin(&peoManage,&accountType,&id,&index);

        if(accountType == STUACCOUNT){

            do{

                ManageSysShowMenuStu();
                printf("\n请输入选择>");
                scanf("%d",&input);

                switch(input){
                    
                    case STU_SHOWMYMESSAGE:
                        ManageSysShowMyMessageStu(&peoManage,id);
                        break;
                    case STU_CHANGEMYMESSAGE:
                        ManageSysChangeMyMessageStu(&peoManage,id);
                        break;
                    case STU_SHOWALLSCORE:
                        ManageSysShowAllScoreStu(&peoManage);
                        break;
                    case STU_SORTBYID:
                        ManageSysSortStuById(&peoManage);
                        break;
                    case STU_SORTBYSCORE:
                        ManageSysSortStuByScore(&peoManage);
                        break;
                    case EXIT:
                        break;
                    default:
                        printf("输入有误");
                        break;
                }

                PRESS_CONTINUE();
                SCREENCLEAN();

            }while(input);
        }
        else if(accountType == TEAACCOUNT){
            
            do{

                ManageSysShowMenuTea();
                printf("\n请输入选择>");
                scanf("%d",&input);

                switch(input){
                    
                    case TEA_SHOWMYMESSAGE:
                        ManageSysShowMyMessageTea(&peoManage,id);
                        break;
                    case TEA_CHANGEMYMESSAGE:
                        ManageSysChangeMyMessageTea(&peoManage,id);
                        break;
                    case TEA_SHOWALLTEAMESSAGE:
                        ManageSysShowAllTeaMessageTea(&peoManage);
                        break;
                    case TEA_SORTTEABYID:
                        ManageSysSortTeaByIdTea(&peoManage);
                        break;
                    case TEA_SHOWALLSTUMESSAGE:
                        ManageSysShowAllStuMessageTea(&peoManage);
                        break;
                    case TEA_ADDSTU:
                        ManageSysAddStuTea(&peoManage);
                        break;
                    case TEA_CHANGESTUMESSAGE:
                        ManageSysChangeStuMessageTea(&peoManage);
                        break;
                    case TEA_CHANGESTUSCORE:
                        ManageSysChangeStuScoreTea(&peoManage);
                        break;
                    case TEAT_DELSTU:
                        ManageSysDelStuTea(&peoManage);
                        break;
                    case TEA_SORTALLSTUBYID:
                        ManageSysSortStuById(&peoManage);
                        break;
                    case TEA_SORTALLSTUBYSCORE:
                        ManageSysSortStuByScore(&peoManage);
                        break;
                    case EXIT:
                        break;
                    default:
                        printf("输入有误");
                        break;
                }

                PRESS_CONTINUE();
                SCREENCLEAN();

            }while(input);
            
        }
        else if(accountType == ROOTACCOUNT){

        }

        // PRESS_CONTINUE();
    }
}

void test02(){

    PeoManage peoManage;
    ManageSysInit(&peoManage);

    TeaManage* p = &(peoManage.teaManage);

    TeaInsert(p,1);
    TeaInsert(p,2);
    TeaInsert(p,2);
    TeaInsert(p,3);
    TeaInsert(p,5);
    TeaInsert(p,6);

    TeaShowAllById(p,1);
    TeaShowAllById(p,6);
    TeaShowAll(p);

    // TeaDelById(p,1);
    // TeaDelById(p,6);
    // TeaDelById(p,3);
    // TeaDelById(p,4);
    // TeaDelById(p,5);
    // TeaDelById(p,2);

    // TeaChangeMessageById(p,1);
    // TeaChangeMessageById(p,3);
    // TeaChangeMessageById(p,6);

    TeaSortById(p);
}

void test01(){

    PeoManage peoManage;
    ManageSysInit(&peoManage);

    StuInsert(&peoManage.stuManage,1);
    StuInsert(&peoManage.stuManage,2);
    StuInsert(&peoManage.stuManage,3);
    StuInsert(&peoManage.stuManage,4);

    for(int i = 1;i <=4;i++){

        StuInputScore(&peoManage.stuManage,i);
        StuShowScore(&peoManage.stuManage,i,i);
    }

    StuShowAll(&peoManage.stuManage);

    StuDelById(&peoManage.stuManage,1);
    StuShowAll(&peoManage.stuManage);

    StuDelById(&peoManage.stuManage,4);
    StuShowAll(&peoManage.stuManage);

    StuDelById(&peoManage.stuManage,3);
    StuShowAll(&peoManage.stuManage);

    StuDelById(&peoManage.stuManage,2);
    StuShowAll(&peoManage.stuManage);

    // StuChangeMessageByIndex(&peoManage.stuManage,1);
    // StuChangeMessageById(&peoManage.stuManage,3);

    // StuChangeScoreByIndex(&peoManage.stuManage,2);
    // StuChangeScoreById(&peoManage.stuManage,3);

    StuSortById(&peoManage.stuManage);
    StuSortByScore(&peoManage.stuManage);
    
    printf("end\n");
   
}
